<template>
  <el-container class="common-layout">
    <el-header height="270px">
      <el-carousel :interval="4000" type="card" height="200px">
        <el-carousel-item v-for="item in backImgs" :key="item">
          <!-- <span class="demonstration">{{ fit }}</span> -->
          <el-image
            style="width: 400px; height: 200px"
            :src="item"
            fit="scale-down"
          ></el-image>
        </el-carousel-item>
      </el-carousel>
    </el-header>
    <el-container>
      <el-main>
        <el-form
          :label-position="labelPosition"
          label-width="100px"
          :model="form"
          style="max-width: 460px"
        >
          <el-form-item label="用户名:">
            <el-input v-model="form.name" placeholder="请输入用户名"></el-input>
          </el-form-item>
          <el-form-item label="密码:">
            <el-input v-model="form.passwd" placeholder="请输入密码"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button
              type="primary"
              @click="submitForm(form.name, form.passwd)"
              >Submit</el-button
            >
            <el-button native-type="reset">Reset</el-button>
          </el-form-item>
        </el-form>
      </el-main>
    </el-container>
    <!-- <el-container>  -->
    <!--  <el-footer>Footer</el-footer>  -->
    <!--</el-container> -->
  </el-container>
  <router-view></router-view>
</template>

<script lang="ts">
import { reactive, ref } from "vue";
import { Common } from "@/api/index";
import { ElMessage } from "element-plus";
import { useRouter } from 'vue-router'

export default {
  setup() {
    const router = useRouter();

    const labelPosition = ref("right");

    const form = reactive({
      name: "",
      passwd: "",
    });

    const backImgs = reactive([
      require("@/assets/img/1.jpg"),
      require("@/assets/img/2.jpg"),
      require("@/assets/img/3.jpg"),
      require("@/assets/img/4.jpg"),
    ]);

    const submitForm = (username: string, passwd: string): void => {
      Common.login({
        userName: username,
        passwd: passwd,
      }).then((response: any) => {
        if (response != undefined && response.status == 200) {
          const data: any = response.data;
          if (data.code != 0) {
            // 登录失败
            ElMessage.error(data.msg)
          } else {
            // if (data.)
            const data1: any = data.data;
            // window.location.href += window.location.href + '/sceneManager'
            ElMessage.info('用户:' + data1.username + '登录成功')
            router.push({ path: 'home' });   
          }
        } else {
          ElMessage.error('登录失败');
        }
      });
    };

    return {
      labelPosition,
      form,
      backImgs,
      submitForm,
    };
  },
};
</script>

<style lang="scss">
.el-form {
  position: relative;
  left: 40%;
}

.el-carousel__item h3 {
  color: #475669;
  font-size: 14px;
  opacity: 0.75;
  line-height: 200px;
  margin: 0;
  text-align: center;
}

.el-carousel__item:nth-child(2n) {
  background-color: #99a9bf;
}

.el-carousel__item:nth-child(2n + 1) {
  background-color: #d3dce6;
}

.common-layout {
  .el-header {
    background-color: transparent;
    color: var(--el-text-color-primary);
    text-align: center;
    line-height: 60px;
  }

  .el-footer {
    background-color: #b3c0d1;
    color: var(--el-text-color-primary);
    text-align: center;
    line-height: 60px;
  }

  .el-footer {
    line-height: 60px;
  }

  .el-aside {
    background-color: #d3d3e6;
    color: var(--el-text-color-primary);
    text-align: center;
    line-height: 200px;
  }

  .el-main {
    background-color: #e9eef3;
    color: var(--el-text-color-primary);
    text-align: center;
    // line-height: 160px;
  }

  body > .el-container {
    margin-bottom: 40px;
  }

  .el-container:nth-child(5) .el-aside,
  .el-container:nth-child(6) .el-aside {
    line-height: 260px;
  }

  .el-container:nth-child(7) .el-aside {
    line-height: 320px;
  }
}
</style>